var datas = [];
var table;
function init() {
	setTimePicker();
	query();
}
function query() {
	var start = $('#startTime').val();
	var end = $('#endTime').val();
	$.getJSON("/rest/newEquipment/getNewEquipments/" + start + "/" + end, function(result) {
		datas = result;
		loadHtml();
	});
}
function loadHtml() {
	if (table) {
		table.getTable().destroy();
	}
	var columns = [ localeTitle.XuHao, localeTitle.SuoShuDiQu, localeTitle.GongChengMingCheng,
			localeTitle.GongChengZiLiaoGuanLi, localeTitle.ChangZhanCTPeiZhiTu, localeTitle.BaoHuJiTongDaoMingMing,
			localeTitle.DingZhiHeChaJiBeiAn, localeTitle.DianWangTiaoZhaQingCe, localeTitle.BaoXinXiTongJieRu,
			localeTitle.XinSheBeiTouChanQiYanShou, localeTitle.DingZhiZhengDingJiXiaFa,
			localeTitle.XuQiTaZhuanYePeiHeGongZuo ];
	var opt = MyTable.getDefaultOptions();
	opt.paging = false;
	opt.scrollY = scrollYHeight+'px';
	opt.columnDefs = [ {
		targets : 0,
		width : '1%'
	}, {
		targets : 1,
		width : '9%'
	}, {
		targets : 2,
		width : '9%'
	}, {
		targets : 3,
		width : '9%'
	}, {
		targets : 4,
		width : '9%'
	}, {
		targets : 5,
		width : '9%'
	}, {
		targets : 6,
		width : '9%'
	}, {
		targets : 7,
		width : '9%'
	}, {
		targets : 8,
		width : '9%'
	}, {
		targets : 9,
		width : '9%'
	}, {
		targets : 10,
		width : '9%'
	}, {
		targets : 11,
		width : '9%'
	} ];
	table = new MyTable("newEquipmentTable", columns, opt);
	table.setDataSet(getDataset()).show();
}
function getDataset() {
	var dataset = [];
	for ( var i in datas) {
		var d = datas[i];
		dataset.push([ Number(i) + 1, str(d.belongArea), str(d.projectName), str(d.projectDataMag),
				str(d.substationCTMap), str(d.protectChannel), str(d.valueInspect), str(d.plantTripRecord),
				str(d.prudentialSystemAccess), str(d.newEquiIn), str(d.valueSetting), str(d.otherMajor) ]);
	}
	return dataset;
}
function str(d) {
	if (d) {
		if (d.length > 50) {
			d = "<span title='" + d + "'>" + d.substring(0, 50) + "   <b>...</b></span>";
		} else {
			if (d == "√") {
				d = "<div class='correct'>" + d + "</div>";
			} else if (d == "×") {
				d = "<div class='error'>" + d + "</div>";
			}
		}
	} else {
		d = '';
	}
	return d;
}
function setTimePicker() {
	$('#startTime').val($('#start').val());
	$('#endTime').val($('#end').val());
	$('#startTime').datetimepicker({
		format : 'yyyy-mm-dd',
		startView : 2,
		minView : 2,
		autoclose : true,
		endDate : new Date(),
		todayHighlight : true
	});
	$('#endTime').datetimepicker({
		format : 'yyyy-mm-dd',
		startView : 2,
		minView : 2,
		autoclose : true,
		endDate : new Date(),
		pickerPosition : 'bottom-left',
		todayHighlight : true
	});
}

function resizeHtml() {
	if (table) {
		table.getTable().draw();
	}
}
